#include "CheckInRecord.h"
#include <iostream>
#include <iomanip>
#include <sstream>
#include <ctime>

CheckInRecord::CheckInRecord()
: roomNumber(0), deposit(0.0f), isCheckedOut(false) {}

std::string getCurrentTime() {
	auto now = std::time(nullptr);
	auto local = *std::localtime(&now);
	std::ostringstream oss;
	oss << std::put_time(&local, "%Y-%m-%d %H:%M");
	return oss.str();
}

CheckInRecord CheckInRecord::fromString(const std::string& line) {
	CheckInRecord rec;
	std::istringstream iss(line);
	iss >> rec.orderId >> rec.idCard >> rec.guestName >> rec.roomType >> rec.roomNumber;
	
	std::string timePart1, timePart2;
	iss >> timePart1 >> timePart2;
	rec.actualCheckInTime = timePart1 + " " + timePart2;
	
	iss >> rec.deposit;
	int flag;
	iss >> flag;
	rec.isCheckedOut = (flag == 1);
	return rec;
}

std::string CheckInRecord::toString() const {
	std::ostringstream oss;
	oss << orderId << " " << idCard << " " << guestName << " " << roomType << " "
	<< roomNumber << " \"" << actualCheckInTime << "\" "
	<< std::fixed << std::setprecision(2) << deposit << " "
	<< (isCheckedOut ? "1" : "0");
	return oss.str();
}

void CheckInRecord::printSlip() const {
	std::cout << "\n" << std::string(50, '=') << "\n";
	std::cout << "            MR酒店 入住登记单\n";
	std::cout << std::string(50, '-') << "\n";
	std::cout << "订单号：" << orderId << "\n";
	std::cout << "姓名：" << guestName << "\n";
	std::cout << "身份证：" << idCard << "\n";
	std::cout << "房型：" << roomType << "\n";
	std::cout << "房号：" << roomNumber << "\n";          // ✅ 显示房号
	std::cout << "入住时间：" << actualCheckInTime << "\n";
	std::cout << "押金金额：" << std::fixed << std::setprecision(2) << deposit << " 元\n";
	std::cout << "状态：已登记入住\n";
	std::cout << std::string(50, '=') << "\n\n";
}
